package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-07-25
 * Time: 17:07
 */
public class Demo15 {
    private static Object locker = new Object();
    public static void main(String[] args) {
        Thread thread = new Thread(() ->{
            while (true) {
                synchronized (locker) {
                    System.out.println("ti wait start");
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("t1, end");
                }
            }
        });
        thread.start();
        Thread thread2 = new Thread(() ->{
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized ((locker)) {
                    System.out.println("t2 noti");
                    locker.notify();
                    System.out.println("t2, end");
                }
            }
        });
        thread2.start();
    }
}
